package com.gec.anan.order.receiver;

import com.gec.anan.common.constant.MqConst;
import com.gec.anan.order.service.OrderInfoService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;

import java.io.IOException;


public class OrderReceiver {

    private OrderInfoService orderInfoService;


    /**
     * 订单分账成功，更新分账状态
     *
     * @param orderNo
     * @param message
     * @param channel
     * @throws IOException
     */
    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(value = MqConst.QUEUE_PROFITSHARING_SUCCESS,durable = "true"),
                    exchange = @Exchange(value = MqConst.EXCHANGE_ORDER),
                    key = {MqConst.ROUTING_PROFITSHARING_SUCCESS}
            )
    )
    public void profitsharingSuccess(String orderNo, Message message, Channel channel) throws IOException {
        orderInfoService.updateProfitsharingStatus(orderNo);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }
}
